package com.guge.sports.service.impl;

import com.guge.sports.entity.Dto.Option;
import com.guge.sports.entity.Dto.StTeacherDto;
import com.guge.sports.entity.StTeacher;
import com.guge.sports.mapper.StTeacherMapper;
import com.guge.sports.service.StTeacherService;
import com.guge.sports.toolPackage.base.BaseService;
import com.guge.sports.toolPackage.utils.ExcelUtils;
import com.guge.sports.toolPackage.utils.FileUploadUtils;
import com.guge.sports.toolPackage.utils.MyPager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author testjava
 * @since 2022-09-14
 */
@Service
public class StTeacherServiceImpl extends BaseService<StTeacher> implements StTeacherService {

    @Autowired
    private StTeacherMapper stTeacherMapper;


   /* //excel导入监听器
    @Autowired
    private StTeacherExcelListener stTeacherExcelListener;*/



    //分页查询
    @Override
    public MyPager<StTeacherDto> selectStTeacherPage(MyPager<StTeacherDto> myPager, StTeacherDto stTeacherDto) {
        List<StTeacherDto> stTeacherDtos = stTeacherMapper.selectStTeacherPage(myPager.calcuStartIndex(), stTeacherDto);
        int count = stTeacherMapper.selectCountStTeacherPage(stTeacherDto);
        return myPager.setTotalCount(count).calcuTotalPage().setList(stTeacherDtos);
    }

    //导入excel数据
    @Override
    public boolean excelImport(MultipartFile uploadFile) {
        List<StTeacher> stTeachers = ExcelUtils.importExcel(uploadFile, StTeacher.class);
        if (stTeachers==null) {
            return false;
        }
        System.out.println(stTeachers);
        return true;
    }

    //导出excel数据
    @Override
    public boolean excelExport(HttpServletResponse httpServletResponse) {
        return ExcelUtils.exportExcel(selectAll(),StTeacher.class,httpServletResponse,"学校教师认证情况");
    }

    // 教师认证年份
    @Override
    public List<Option> getGoStateTimeList() {
        return stTeacherMapper.getGoStateTimeList();
    }


    //下载表格
    @Override
    public boolean excelDownload(HttpServletResponse response) {
       return FileUploadUtils.download(response,"/backend/download/excel/03.xlsx");

    }


}
